{include file="public/header" /} {include file="public/lefter" /}
{css href="__PLUG__/bootstrapvalidator/css/bootstrapValidator.min.css" /}
<link rel="stylesheet" type="text/css" href="__PLUG__/webuploader/webuploader.css">
<style type="text/css">
	.webuploader-pick {
		border-radius: 0px;
	}
	
	#delexpimg {
		height: 40px;
		margin-left: 5px;
	}
	.edui-default .edui-editor-toolbarboxouter {
		background-image: linear-gradient(to bottom, #F1F1F1, #f1f1f1);
	}
	.edui-default .edui-editor {
		border-radius: 0px;
    }
	    
</style>
<div class="container-fluid box-a">
	<div class="nav-c">
		<span class="glyphicon glyphicon-tag">&nbsp;<span id="">编辑文章</span>
	</div>
	<box class="box-b">
		<div class="divs">
			<div style="height: 100%;" class="row">
				<div class="page-header page-s">
					<h5>编辑文章<small></small></h5>
				</div>
				<form id="articleform" role="form" action="" method="post">
					<input type="hidden" name="arid" value="{$adb['id']}" />
					<div class="col-md-8 col-sm-8">
						<div class="form-group">
							<label for="inputtitle" class="control-label">文章标题</label>
							<input type="text" name="title" class="form-control" placeholder="文章标题" value="{$adb['title']}" />
						</div>
						<div class="form-group">
							<label for="inputstitle" class="control-label">摘要</label>
							<input type="text" name="keyword" class="form-control" placeholder="摘要" value="{$adb['keyword']}" />
						</div>
                        
						<div class="form-group">
							<label for="inputhelp" class="control-label">文章内容</label>
							<script id="aedit" name="content" type="text/plain" style="height: 380px;width: 100%;">{$adb['content']}</script>
						</div>
					</div>
					<!------------------------------right---------------------------------------------------------->
					<div class="col-md-4">
						<label>发布设置</label>
					</div>
					<div class="col-md-4">
						{:hook('down_fee', ['pos'=>'edit','aid'=>$adb['id']])}
						<div class="panel panel-s panel-default">
							<div class="panel-body">
								<div class="page-header page-0">
									<h5 style="font-weight:800">所属分类</h5>
								</div>
								<div class="col-sm-12">									
									{volist name="tree" id="vo"}
									<div class="checkbox">
										<label>
                                        <input name="sort[]" type="checkbox" value="{$vo.id}" {volist name="$adb_sort" id="va"}{if condition="($va == $vo.id)"}checked="checked"{/if}{/volist}> <strong style="color:#336699;">{$vo.sort_name}</strong>
                                    </label>
									</div>
									{/volist}
									<a class="btn btn-default btn-sm" href="{:URL('/admin/article/sorts')}" role="button">添加分类</a>
								</div>
							</div>
						</div>
						<div class="panel panel-s panel-default">
							<div class="panel-body">
								<div class="page-header page-0">
									<h6 style="font-weight:800">特色图片&nbsp;320*180</h6>
								</div>
								<label for="inputcopyright" class="sr-only">特色图片</label>

								<!--dom结构部分-->
								<div id="uploader-demo">
									<!--用来存放item-->
									<div id="fileList" class="uploader-list">
										{if condition="$adb.thumb_img neq null"}
										<div id="divimg" class="file-item thumbnail">
											<img id="imgid" src="__PUBLIC__{$adb['thumb_img']}">
										</div>
										{/if}
									</div>
									<div class="pull-left" id="filePicker">选择图片</div>
									<button type="button" id="delimgs" class="btn btn-default pull-right">清除</button>
								</div>
							</div>
						</div>

						<input type="hidden" name="thumb_img" id="imgs" value="{$adb['thumb_img']}" />
						<div class="form-group">
							<div class="pull-right">
								<a class="btn btn-warning" href="{:URL('/admin/article')}" role="button">返回列表</a>
								<button type="submit" id="subadd" class="btn btn-primary">发布编辑</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
	</box>
</div>
{include file="public/flooter" /}
{js href="__PLUG__/bootstrapvalidator/js/bootstrapValidator.min.js" /}
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__PLUG__/webuploader/webuploader.js"></script>
<script type="text/javascript">
	$(document).ready(function() {		
		$('#subadd').click(function() {
			var str_data = $("#articleform").serialize();
			
			$.ajax({
				type: "post",
				url: "edit",
				data: str_data,
				success: function(msg) {
					if(msg=='error'){
						layer.msg('修改失败,请填写完整！')
					}else{
						layer.msg('编辑成功', {
                            time: 2000, //20s后自动关闭
                        },function(){
                            window.location.href='{:URL("admin/article/edit")}?aid={$adb[\'id\']}';
                        });
						
					}
					
				}
			});
			return false;
		});		
	});
</script>

<script type="text/javascript">
// 图片上传demo
jQuery(function() {
    var $ = jQuery,
        $list = $('#fileList'),
        // 优化retina, 在retina下这个值是2
        ratio = window.devicePixelRatio || 1,

        // 缩略图大小
        thumbnailWidth = 100 * ratio,
        thumbnailHeight = 100 * ratio,

        // Web Uploader实例
        uploader;

    // 初始化Web Uploader
    uploader = WebUploader.create({

        // 自动上传。
        auto: true,

        // swf文件路径
        swf: '__PLUG__/webuploader/Uploader.swf',
        // 文件接收服务端。
        server: 'upload',
        // 选择文件的按钮。可选。
        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
        pick: '#filePicker',
        // 只允许选择文件，可选。
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        }
    });

    // 当有文件添加进来的时候
    uploader.on( 'fileQueued', function( file ) {
    	$("#divimg").remove();
        var $li = $(
                '<div id="divimg" class="file-item thumbnail">' +
                    '<img id="imgid">' +
                    '<div class="info">' + file.name + '</div>' +
                '</div>'
                ),
            $img = $li.find('img');

        $list.append( $li );

        // 创建缩略图
        uploader.makeThumb( file, function( error, src ) {
            if ( error ) {
                $img.replaceWith('<span>不能预览</span>');
                return;
            }

            $img.attr( 'src', src );
        }, thumbnailWidth, thumbnailHeight );
    });

    // 文件上传过程中创建进度条实时显示。
    uploader.on( 'uploadProgress', function( file, percentage ) {
        var $li = $( '#'+file.id ),
            $percent = $li.find('.progress span');

        // 避免重复创建
        if ( !$percent.length ) {
            $percent = $('<p class="progress"><span></span></p>')
                    .appendTo( $li )
                    .find('span');
        }

        $percent.css( 'width', percentage * 100 + '%' );
    });

    // 文件上传成功，给item添加成功class, 用样式标记上传成功。
    uploader.on( 'uploadSuccess', function( file,response ) {
        $( '#'+file.id ).addClass('upload-state-done');
        var furl='/uploads/'+response._raw;
        $('#imgid').attr('src','__PUBLIC__'+furl);
        $('#imgs').val(furl);
         
    });

    // 文件上传失败，现实上传出错。
    uploader.on( 'uploadError', function( file ) {
        var $li = $( '#'+file.id ),
            $error = $li.find('div.error');

        // 避免重复创建
        if ( !$error.length ) {
            $error = $('<div class="error"></div>').appendTo( $li );
        }

        $error.text('上传失败');
    });

    // 完成上传完了，成功或者失败，先删除进度条。
    uploader.on( 'uploadComplete', function( file ) {
        $( '#'+file.id ).find('.progress').remove();
    });
});
</script>

<script type="text/javascript">
	$("#delimgs").click(function(){
       $('#divimg').remove();
       $('#imgs').val('');
   });
</script>

<script type="text/javascript">
//实例化编辑器
    var ue = UE.getEditor('aedit',{
    	//为编辑器实例添加一个路径，这个不能被注释
        UEDITOR_HOME_URL: "{:get_root()}/public/ueditor/" ,
        // 服务器统一请求接口路径
        serverUrl: "{:url('/admin/ueditor/index')}",
        //enableAutoSave: false,
        toolbars: [[
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
            'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
            'directionalityltr', 'directionalityrtl', 'indent', '|',
            'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
            'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
            'simpleupload', 'insertimage', 
            //'emotion',
            'scrawl', 'insertvideo',
            //'music',
            'attachment',
            //'map', 'gmap',
            //'insertframe',
            'insertcode',
            //'webapp',
            'pagebreak', 'template', 'background', '|',
            'horizontal',
            //'date','time',
            'spechars', 'snapscreen', 'wordimage', '|',
            'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
            //'print',
            'preview', 'searchreplace', 
            //'drafts',
            //'help'
        ]]
    	
    });

</script>

